import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { selfBuildHousePointList } from '@gis/lib/api';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { openSelfBuildHouseDialog } from '../../../../views/self-built-house/details/details.js';
import { bdToGd } from '../../js/translator.js';
import get from 'lodash-es/get.js';

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = 'zjfybyh';
    super.create();
  }
  getPosition(data) {
    return get(data, 'lnglat');
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  onClick() {
    openSelfBuildHouseDialog(this.data);
  }
}

export default class Zjfybyh extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const data = await handleCommonRes(selfBuildHousePointList, { area_code: area_code, hidden_danger_level: 2 });
    return data && data.length
      ? data
          .filter((item) => item.longitude && item.latitude)
          .map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }))
      : [];
  }
}
